/**
 * Created by lihui on 2017/8/5.
 */
import axios from 'axios'
import { Toast } from 'mint-ui';
import host from '../config'
import Router from 'vue-router'
// let token = window.localStorage.getItem('token')
let route = new Router()


 let refresh = function () {
   let that = this
   if(!window.localStorage.getItem('token') ||window.localStorage.getItem('token') == '' || window.localStorage.getItem('token') == undefined || window.localStorage.getItem('token') == null) {
     route.push('/login')
     return
   }
   axios({
     method: 'get',
     headers: {'Authorization': window.localStorage.getItem('token')},
     url: host.host + "/api/usr/refreshToken"
   }).then(function (data) {
     if(data.data.code === 200){
       window.localStorage.setItem("token",data.data.data.token)
     } else{
       window.localStorage.removeItem("token")
       route.push('/login')
     }
   })
 }

export default refresh
